package Q1816;

/**
 * 截断句子
 * @author 23737
 * @time 2021.12.6
 */
public class Test {
    public static void main(String[] args) {

    }
}

class Solution {
    public String truncateSentence(String s, int k) {
        String[] split = s.split(" ");
        if(k > split.length){
            return null;
        }
        StringBuilder str = new StringBuilder();
        for(int i=0; i<k; i++){
            if(i == k-1){
                str.append(split[i]);
            }else{
                str.append(split[i]+" ");
            }
        }
        return str.toString();
    }
}
